<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>方案页面</title>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <script src="../../res/js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../res/layui/layui.js"></script>
    <script src="../../res/js/login_common.js" type="text/javascript" charset="utf-8"></script>
    <style>
        .layui-inline{
            margin-top: 10px;
        }
    </style>
    <script>
        $(function(){
            $("#search").on("click",function(){
                //执行重载
                table2.reload({
                    url:'../../mentalityas/findAll',
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        schemeName: $("#schemeName").val(),
                        startTime: $("#startTime").val(),
                        endTime: $("#endTime").val()
                    }
                });
            })
        })
    </script>
</head>
<body>
    <div class="layui-inline">
        <label class="layui-form-label" style="width:85px;">方案名</label>
        <div class="layui-input-inline">
            <input type="text" placeholder="请输入方案名" id="schemeName" class="layui-input" style="width:200px;float:left;height:32px;">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label" style="width:90px;">方案日期</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="startTime" autocomplete="off" name="startTime" placeholder="请输入开始时间" style="width:200px;float:left;height:32px;">
            <span style="float:left;">—</span>
            <input type="text" class="layui-input" id="endTime" name="endTime" autocomplete="off"  placeholder="请输入结束时间" style="width:200px;float:left;height:32px;">
        </div>
    </div>
<button type="button" class="layui-btn layui-btn-normal layui-btn-sm" id="search" style="margin-left: 10px;">搜索</button>
<table class="layui-hide" id="test" lay-filter="test"></table>
    <script type="text/javascript" charset="utf-8">
        var table2=null;
        var name = "";
        var start="";
        var end="";
        var dt=null;
        var str = "";
        layui.use(['table','laydate'],function(){
            var table = layui.table
            dt=laydate = layui.laydate;
            table2=table.render({
                elem: '#test'
                ,url:'../../mentalityas/findAll'
                ,toolbar: '#toolbarDemo'
                ,page: true //开启分页
                ,title: '方案表'
                ,cols: [[
                     {type:'checkbox'}
                    ,{field:'coachName', title:'教练姓名', width:100}
                    ,{field:'schemeName', title:'方案名称',width:120}
                    ,{field:'year', title:'方案年度', width:120}
                    ,{field:'month', title:'方案月份', width:120 ,sort: true,templet:'#titleTpl'}
                    ,{field:'schemeType', title:'方案类型', width:150}
                    ,{field:'file1', title:'附件1',width:100,toolbar: '#file1'}
                    ,{field:'file2', title:'附件2',width:100,toolbar: '#file2'}
                    ,{field:'file3', title:'附件3',width:100,toolbar: '#file3'}
                    ,{fixed:'right', title:'操作', toolbar: '#barDemo', width:360}
                ]]
                ,done: function(res, curr, count){
                    //如果是异步请求数据方式，res即为你接口返回的信息。
                    //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                    // console.log(res.data);
                    //laydate.render(); //日期选择器，可以写在table的回调中
                    date();
                }
        });
            /* 头部工具栏监听 */
            table.on('toolbar(test)', function(obj){
                var checkStatus = table.checkStatus(obj.config.id);
                var data = checkStatus.data; //获取选中的数据
                switch(obj.event){
                    case 'addBtn':
                        //iframe层
                        layer.open({
                            type: 2,
                            title: '新增页面',
                            shadeClose: true,
                            shade: 0.8,
                            area: ['70%', '80%'],
                            content: 'MentalityAtsSchemeAddorUpdate.html', //iframe的url
                            end:function(){
                                table2.reload();
                            }
                        });
                        break;
                    case 'delete':
                        if(data.length === 0){
                            layer.msg('请选择一行');
                        } else {
                            layer.confirm('确定需要删除吗?', function(index){
                                var ids = "";
                                $.each(data,function(index,item){
                                    ids+=item.schemeId+",";
                                })
                                var url = "../../mentalityas/deleteAll";
                                var datas ={ids:ids};
                                $.post(url,datas,function(obj){
                                    if(obj.num==1){
                                        layer.msg(obj.msg,{
                                            icon:1,
                                            time:1000 //1秒关闭(如果不配置默认三秒)
                                        },function(){
                                            //刷新当前页面
                                            $(".layui-laypage-btn").click();
                                        });
                                    }else{
                                        layer.msg(obj.msg);
                                    }
                                },'json');
                            });
                        }
                        break;
                };
            });
            table.on('tool(test)', function(obj){
                var data = obj.data;
                if(obj.event === 'del'){
                    layer.confirm('真的删除行么', function(index){
                        obj.del();
                        layer.close(index);
                        var url="../../mentalityas/delete";
                        var dataone={"id":data.schemeId};
                        $.post(url,dataone,function(obj){
                            if(obj.num==1){
                                layer.msg(obj.msg,{
                                    icon:1,
                                    time:1000 //1秒关闭(如果不配置默认三秒)
                                },function(){
                                    //刷新当前页面
                                    $(".layui-laypage-btn").click();
                                });
                            }else{
                                layer.msg(obj.msg);
                            }
                        },"json")
                    });
                } else if(obj.event === 'edit'){
                    //iframe层
                    layer.open({
                        type: 2,
                        title: '修改页面',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['70%', '80%'],
                        content: 'MentalityAtsSchemeAddorUpdate.html?id='+data.schemeId, //iframe的url
                        end:function(){
                            table2.reload();
                        }
                    });
                } else if(obj.event === 'feedback'){
                    //iframe层
                    layer.open({
                        type: 2,
                        title: '反馈页面',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['40%', '80%'],
                        content: 'updateMentalityAtsScheme.html?id='+data.schemeId, //iframe的url
                        end:function(){
                            table2.reload();
                        }
                    });
                } else if(obj.event === 'applyFor'){
                    //iframe层
                    layer.open({
                        type: 2,
                        title: '专家咨询页面',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['50%', '55%'],
                        content: 'MentalityAtsSchemeExpertAdd.html?id='+data.schemeId, //iframe的url
                        end:function(){
                            table2.reload();
                        }
                    });
                }else if(obj.event === 'look'){
                    //iframe层
                    layer.open({
                        type: 2,
                        title: '查看页面',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['80%', '80%'],
                        content: 'MentalityAtsSchemeLook.html?id='+data.schemeId, //iframe的url
                        end:function(){
                            table2.reload();
                        }
                    });
                }else if(obj.event === 'check'){
                    layer.open({
                        type: 2,
                        title:'审核',
                        shadeClose:true,
                        shade:0.8,
                        area:['60%','73%'],//'../../pages/xy/userForm.html?id='
                        content: ['check.html?id='+data.schemeId], //数组第二项即吸附元素选择器或者DOM
                        end:function(){
                            //刷新表格
                            table2.reload();
                        }
                    });
                }else if(obj.event === 'reply'){
                    layer.open({
                        type: 2,
                        title:'专家回复',
                        shadeClose:true,
                        shade:0.8,
                        area:['55%','53%'],//'../../pages/xy/userForm.html?id='
                        content: ['reply.html?id='+data.schemeId], //数组第二项即吸附元素选择器或者DOM
                        end:function(){
                            //刷新表格
                            table2.reload();
                        }
                    });
                }else if(obj.event === 'daochu'){
                    window.location.href="../../mentalityas/derive?id="+data.schemeId;
                }
            });
        }) ;
        function date(){
            //年月选择器
            dt.render({
                elem: '#startTime'
                ,type: 'month'
                ,trigger: 'click'
            });
            dt.render({
                elem: '#endTime'
                ,type: 'month'
                ,trigger: 'click'
            });
        }
    </script>

    <script type="text/html" id="toolbarDemo">
        <div class="layui-input-inline">
            {{# if(loginObj.manager.usType=="教练"){ }}
            <button class="layui-btn layui-btn-sm" lay-event="addBtn">新增</button>
            {{# } }}
            <button class="layui-btn layui-btn-danger layui-btn-sm " lay-event="delete">删除数据</button>
        </div>
    </script>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="daochu">导出</a>
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="look">查看</a>
        {{# if(loginObj.manager.usType=="教练"){ }}
        {{# if(d.auditState==10||d.auditState==20||d.auditState==30||d.auditState==40){ }}
        <a class="layui-btn layui-btn-xs layui-btn-disabled" lay-event="edit">编辑</a>
        {{# }else{ }}
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
        {{# } }}
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        {{# if(d.auditState==10||d.auditState==20||d.auditState==30||d.auditState==40){ }}
        <a class="layui-btn layui-btn-warm layui-btn-xs layui-btn-disabled" lay-event="applyFor">申请专家咨询</a>
        {{# }else{ }}
        <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="applyFor" id="expert">申请专家咨询</a>
        {{# } }}
        {{# if(d.auditState==40){ }}
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="feedback">反馈</a>
        {{# } }}
        {{# } }}
        {{# if(loginObj.manager.usType=="领导"){ }}
        <a class="layui-btn layui-btn-xs" lay-event="check">立即审核</a>
        {{# } }}
        {{# if(loginObj.manager.usType=="专家"){ }}
        <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="reply">回复</a>
        {{# } }}
    </script>
    <script type="text/html" id="file1">
        {{# if(d.file1==null||d.file1==''){ }}
            无
        {{# }else{ }}
        <a href="../..{{d.file1}}" class="layui-btn layui-btn-xs" onclick="dd('{{d.schemeId}}');">下载</a>
        {{# } }}
    </script>
    <script type="text/html" id="file2">
        {{# if(d.file2==null||d.file2==''){ }}
            无
        {{# }else{ }}
        <a href="../..{{d.file2}}" class="layui-btn layui-btn-xs" onclick="dd('{{d.schemeId}}');">下载</a>
        {{# } }}
    </script>
    <script type="text/html" id="file3">
        {{# if(d.file3==null||d.file3==''){ }}
            无
        {{# }else{ }}
        <a href="../..{{d.file3}}" class="layui-btn layui-btn-xs" onclick="dd('{{d.schemeId}}');">下载</a>
        {{# } }}
    </script>
    <script>
        function dd(obj){
            var id = loginObj.manager.usWaiid;
            var url = "../../mentalityas/updateByAthleteId";
            var data = {id:id,schemeId:obj};
            $.post(url,data,function(obj){

            },"json");
        }
    </script>
</body>
</html>